<?php

class openapi_log {

    public function __construct() {
        $this->reqModel = app::get('openapi')->model('request_log');
        $this->resModel = app::get('openapi')->model('response_log');
    }

    public function request($api_name, $task_id, $appParams, $responseData, $flag, $status, $msg, $original_task_id = null, $original_num = null) {
        $data['api_name'] = $api_name;
        $data['task_id'] = $task_id;
        $data['appParams'] = $appParams;
        $data['responseData'] = $responseData;
        $data['flag'] = $flag;
        $data['status'] = $status == 'succ' ? 'succ' : 'fail';
        $data['msg'] = $msg;
        $data['createtime'] = time();
        $data['next_retry_time'] = time();
        $data['original_num'] = $original_num;
        $data['original_task_id'] = $original_task_id;
        $this->reqModel->save($data);
    }

    public function response($api_name, $task_id, $appParams, $responseData, $flag, $status, $msg, $original_num = null) {
        $data['api_name'] = $api_name;
        $data['task_id'] = $task_id;
        $data['appParams'] = $appParams;
        $data['responseData'] = $responseData;
        $data['flag'] = $flag;
        $data['status'] = $status ? 'succ' : 'fail';
        $data['msg'] = $msg;
        $data['createtime'] = time();
        $data['last_modified'] = time();
        $data['original_num'] = $original_num;
        $this->resModel->save($data);
    }
} // END class openapi_log




